package net.jonbuck.tassoo.ui.util;

import net.jonbuck.tassoo.util.DateHelperUtils;

import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

/**
 * 
 * 
 * @since 1.0.0
 */
public class DateFieldHelper extends SelectionAdapter {

	/** ... TODO Javadoc ... */
	private CalendarCombo dateField;
	
	/** ... TODO Javadoc ... */
	private Button dateHelperButton;
	
	/**
	 * 	
	 * @param dateField
	 * @param dateHelperButton
	 */
	public DateFieldHelper(CalendarCombo dateField, Button dateHelperButton) {
		super();
		this.dateField = dateField;
		this.dateHelperButton = dateHelperButton;
	}

	/**
	 * 
	 */
	public void widgetSelected(SelectionEvent e) {
		Menu menu = new Menu(dateHelperButton);
		MenuItem today = new MenuItem(menu, SWT.PUSH);
		today.setText("Today");
		today.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addDays(0));
			}
		});
		MenuItem tomorrow = new MenuItem(menu, SWT.PUSH);
		tomorrow.setText("Tomorrow");
		tomorrow.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addDays(1));
			}
		});
		MenuItem dayAftertomorrow = new MenuItem(menu, SWT.PUSH);
		dayAftertomorrow.setText("The Day After Tomorrow");
		dayAftertomorrow.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addDays(2));
			}
		});
		new MenuItem(menu, SWT.SEPARATOR | SWT.HORIZONTAL);
		MenuItem oneWeek = new MenuItem(menu, SWT.PUSH);
		oneWeek.setText("In 1 Week");
		oneWeek.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addWeeks(1));
			}
		});
		MenuItem twoWeeks = new MenuItem(menu, SWT.PUSH);
		twoWeeks.setText("In 2 Weeks");
		twoWeeks.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addWeeks(2));
			}
		});
		MenuItem threeWeeks = new MenuItem(menu, SWT.PUSH);
		threeWeeks.setText("In 3 Weeks");
		threeWeeks.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addWeeks(3));
			}
		});
		new MenuItem(menu, SWT.SEPARATOR | SWT.HORIZONTAL);
		MenuItem oneMonth = new MenuItem(menu, SWT.PUSH);
		oneMonth.setText("In 1 Month");
		oneMonth.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(1));
			}
		});
		MenuItem twoMonths = new MenuItem(menu, SWT.PUSH);
		twoMonths.setText("In 2 Months");
		twoMonths.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(2));
			}
		});
		MenuItem threeMonths = new MenuItem(menu, SWT.PUSH);
		threeMonths.setText("In 3 Months");
		threeMonths.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(3));
			}
		});
		MenuItem fourMonths = new MenuItem(menu, SWT.PUSH);
		fourMonths.setText("In 4 Months");
		fourMonths.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(4));
			}
		});
		MenuItem fiveMonths = new MenuItem(menu, SWT.PUSH);
		fiveMonths.setText("In 5 Months");
		fiveMonths.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(5));
			}
		});
		MenuItem sixMonths = new MenuItem(menu, SWT.PUSH);
		sixMonths.setText("In 6 Months");
		sixMonths.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addMonths(6));
			}
		});
		new MenuItem(menu, SWT.SEPARATOR | SWT.HORIZONTAL);
		MenuItem oneYear = new MenuItem(menu, SWT.PUSH);
		oneYear.setText("In 1 Year");
		oneYear.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				dateField.setDate(DateHelperUtils.addYears(1));
			}
		});
		menu.setVisible(true);
	}

}
